import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { Layout } from 'antd-v4';
import classNames from 'classnames';
import { Component } from 'react';
import GlobalHeader from './components/GlobalHeader';
import TopNavHeader from './components/TopNavHeader';
import './Header.less';
import { clearMenuItem } from './utils/utils';
var Header = Layout.Header;

var HeaderView = /*#__PURE__*/function (_Component) {
  _inherits(HeaderView, _Component);

  var _super = _createSuper(HeaderView);

  function HeaderView() {
    var _this;

    _classCallCheck(this, HeaderView);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _this.renderContent = function () {
      var _this$props = _this.props,
          isMobile = _this$props.isMobile,
          onCollapse = _this$props.onCollapse,
          navTheme = _this$props.navTheme,
          layout = _this$props.layout,
          headerRender = _this$props.headerRender,
          headerContentRender = _this$props.headerContentRender;
      var isTop = layout === 'top';
      var clearMenuData = clearMenuItem(_this.props.menuData || []);

      var defaultDom = _jsx(GlobalHeader, _objectSpread(_objectSpread({
        onCollapse: onCollapse
      }, _this.props), {}, {
        menuData: clearMenuData,
        children: headerContentRender && headerContentRender(_this.props, null)
      }));

      if (isTop && !isMobile) {
        defaultDom = _jsx(TopNavHeader, _objectSpread(_objectSpread({
          theme: navTheme,
          mode: "horizontal",
          onCollapse: onCollapse
        }, _this.props), {}, {
          menuData: clearMenuData
        }));
      }

      if (headerRender && typeof headerRender === 'function') {
        return headerRender(_this.props, defaultDom);
      }

      return defaultDom;
    };

    return _this;
  }

  _createClass(HeaderView, [{
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props2 = this.props,
          fixedHeader = _this$props2.fixedHeader,
          layout = _this$props2.layout,
          propsClassName = _this$props2.className,
          style = _this$props2.style,
          navTheme = _this$props2.navTheme,
          collapsed = _this$props2.collapsed,
          siderWidth = _this$props2.siderWidth,
          hasSiderMenu = _this$props2.hasSiderMenu,
          isMobile = _this$props2.isMobile,
          prefixCls = _this$props2.prefixCls,
          headerHeight = _this$props2.headerHeight;
      var needFixedHeader = fixedHeader || layout === 'mix';
      var isTop = layout === 'top';
      var needSettingWidth = needFixedHeader && hasSiderMenu && !isTop && !isMobile;
      var className = classNames(propsClassName, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-fixed-header"), needFixedHeader), _defineProperty(_classNames, "".concat(prefixCls, "-fixed-header-action"), !collapsed), _defineProperty(_classNames, "".concat(prefixCls, "-top-menu"), isTop), _defineProperty(_classNames, "".concat(prefixCls, "-header-").concat(navTheme), navTheme && layout !== 'mix'), _classNames));
      /** 计算侧边栏的宽度，不然导致左边的样式会出问题 */

      var width = layout !== 'mix' && needSettingWidth ? "calc(100% - ".concat(collapsed ? 48 : siderWidth, "px)") : '100%';
      var right = needFixedHeader ? 0 : undefined;
      return _jsxs(_Fragment, {
        children: [needFixedHeader && _jsx(Header, {
          style: {
            height: headerHeight,
            lineHeight: "".concat(headerHeight, "px"),
            background: 'transparent'
          }
        }), _jsx(Header, {
          style: _objectSpread({
            padding: 0,
            height: headerHeight,
            lineHeight: "".concat(headerHeight, "px"),
            width: width,
            zIndex: layout === 'mix' ? 100 : 19,
            right: right
          }, style),
          className: className,
          children: this.renderContent()
        })]
      });
    }
  }]);

  return HeaderView;
}(Component);

export default HeaderView;